<template>
	<!-- 任务管理模块-核保分单任务管理-核保任务分配页面 -->
	<div class="fillcontain">
		<!-- 查询条件 -->
		<div class="fastQuery">
			<el-row>
				<el-col :span="2" class="fastQuery_title"><i class="el-icon-tickets"></i><span> 查询条件</span></el-col>
				<!-- <el-col :span="2" class="fastQuery_title" ><i class="el-icon-tickets" ></i><span @click="showOrders"> 排序条件</span></el-col> -->
				<el-col :span="10">
				</el-col>
				<el-col :span="4" class="moreCondition">
					<span v-if="!isShow" @click="showorhide">更多条件 <i class="el-icon-d-arrow-right"></i></span>
					<span v-if="isShow" @click="showorhide">收起 <i class="el-icon-d-arrow-left"></i></span>
				</el-col>
				<el-col :span="8"></el-col>
			</el-row>
		</div>
		<el-form v-show="isShow" :model="searchParams" label-width="100px" class="search_container lineH">
			<el-row>
				<el-col :span="6" class="common-box">
					<el-form-item label="受理号" prop="caseno">
						<el-input v-model="searchParams.caseno" placeholder="受理号" clearable></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="6" class="common-box">
					<el-form-item label="保单号" prop="chdrnum">
						<el-input v-model="searchParams.chdrnum" placeholder="保单号" clearable></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="6" class="common-box">
					<el-form-item label="任务级别" prop="level">
						<el-select v-model="searchParams.level" placeholder="任务级别">
							<el-option v-for="item in levels" :key="item.value" :label="item.name" :value="item.value">
							</el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="6" class="common-box">
					<el-form-item label="扫描时间(起始)" prop="begintime">
						<el-date-picker v-model="searchParams.begintime" type="date" value-format="yyyy-MM-dd"
							format="yyyy-MM-dd" placeholder="选择日期" @change="clearTimeSetDefault">
						</el-date-picker>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row>
				<el-col :span="6" class="common-box">
					<el-form-item label="扫描时间(结束)" prop="lasttime">
						<el-date-picker v-model="searchParams.lasttime" type="date" value-format="yyyy-MM-dd"
							format="yyyy-MM-dd" placeholder="选择日期" @change="clearTimeSetDefault">
						</el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="6" class="common-box">
					<el-form-item label="任务上传时间(起始)" prop="tskbgntime">
						<el-date-picker v-model="searchParams.tskbgntime" type="date" value-format="yyyy-MM-dd"
							format="yyyy-MM-dd" placeholder="选择日期" @change="clearTimeSetDefault">
						</el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="6" class="common-box">
					<el-form-item label="任务上传时间(结束)" prop="tskendtime">
						<el-date-picker v-model="searchParams.tskendtime" type="date" value-format="yyyy-MM-dd"
							format="yyyy-MM-dd" placeholder="选择日期" @change="clearTimeSetDefault">
						</el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="6" class="common-box">
					<el-form-item label="被保人姓名" prop="insured">
						<el-input v-model="searchParams.insured" placeholder="被保人姓名" clearable></el-input>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row>
				<el-col :span="6" class="common-box">
					<el-form-item label="投保人姓名" prop="policyer">
						<el-input v-model="searchParams.policyer" placeholder="投保人姓名" clearable></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="6" class="common-box">
					<el-form-item label="机构" prop="orgId">
						<el-select clearable v-model="searchParams.orgId" filterable placeholder="">
						  <el-option
						      v-for="item in ssyMap"
						      :key="item.sbusiorgid"
						      :label="item.sorgname"
						      :value="item.sbusiorgid">
						  </el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="6" class="common-box">
					<el-form-item label="保单类型" prop="insmain">
						<el-select v-model="searchParams.insmain" placeholder="保单类型" clearable>
							<el-option v-for="item in insmains" :key="item.value" :label="item.name"
								:value="item.value">
							</el-option>
						</el-select>
					</el-form-item>
				</el-col>

				<el-col :span="6" class="common-box">
					<el-form-item label="渠道" prop="channel">
						<el-select v-model="searchParams.channel" placeholder="渠道" clearable>
							<el-option v-for="item in preChannelTypes" :key="item.value" :label="item.name"
								:value="item.value">
							</el-option>
						</el-select>
					</el-form-item>
				</el-col>

			</el-row>
			<el-row>
				<el-col :span="6" class="common-box" v-if="flag=='deassign'">
					<el-form-item label="任务状态" prop="taskstatus">
						<el-select v-model="searchParams.taskstatus" placeholder="任务状态" clearable>
							<el-option v-for="item in taskstatus_deassign" :key="item.value" :label="item.name"
								:value="item.value">
							</el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="6" class="common-box" v-if="flag=='reassign'">
					<el-form-item label="任务状态" prop="taskstatus">
						<el-select v-model="searchParams.taskstatus" placeholder="任务状态" clearable>
							<el-option v-for="item in taskstatus_reassign" :key="item.value" :label="item.name"
								:value="item.value">
							</el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="6" class="common-box">
					<el-form-item label="存仓号" prop="depotno">
						<el-input v-model="searchParams.depotno" placeholder="存仓号" clearable></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="6" class="common-box">
					<el-form-item label="电子投保标识" prop="appFrom">
						<el-select v-model="searchParams.appFrom" placeholder="电子投保标识" clearable>
							<el-option v-for="item in appFroms" :key="item.value" :label="item.label"
								:value="item.value">
							</el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="6" class="common-box">
					<el-form-item label="电子投保标识号" prop="serno">
						<el-input v-model="searchParams.serno" placeholder="电子投保标识号" clearable></el-input>
					</el-form-item>
				</el-col>

			</el-row>
			<el-row>
				<el-col :span="6" class="common-box">
					<el-form-item label="历史处理人" prop="historyHandler">
						<el-input v-model="searchParams.historyHandler" placeholder="历史处理人" clearable></el-input>
					</el-form-item>
				</el-col>
        <!--    第二被保人需求  start          -->
        <el-col :span="6" class="common-box">
          <el-form-item label="第二被保人姓名" prop="secondInsuredName">
            <el-input clearable v-model="searchParams.secondInsuredName" placeholder="第二被保人姓名"></el-input>
          </el-form-item>
        </el-col>
        <!--    第二被保人需求  end          -->
				<el-col :span="24" class="text_right" tyle="float: right;" v-if="flag=='deassign'">
					<el-button type="primary" icon="el-icon-search" @click="search"></el-button>
					<el-button type="primary" plain icon="el-icon-refresh" @click="resetSearch"></el-button>
				</el-col>
				<el-col :span="6" class="common-box" v-if="flag =='reassign'">
					<el-form-item label="检出人" prop="checkoutId">
						<el-input v-model="searchParams.checkoutId" placeholder="检出人" clearable></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="6" class="text_right" style="float: right;" v-if="flag =='reassign'">
					<el-button type="primary" icon="el-icon-search" @click="search"></el-button>
					<el-button type="primary" plain icon="el-icon-refresh" @click="resetSearch"></el-button>
				</el-col>
			</el-row>
		</el-form>
		<div class="contain">
			<!-- 操作按钮 -->
			<el-row class="pb10">
				<el-col :span="24">
          <!-- 总公司用户按钮 -->
          <el-button type="danger" plain @click="userListGoHead">总公司</el-button>
          <!-- 非总公司用户按钮 -->
          <el-button type="danger" plain @click="userListGoNotHead">非总公司</el-button>
          <el-button type="danger" plain @click="userListGo">用户列表</el-button>
				</el-col>
			</el-row>

			<!-- 查询结果 -->
			<div class="table_container">
				<el-table ref="multipleDataTable" v-loading="loading" :data="tableData" highlight-current-row
					header-cell-class-name="table-header-class" style="width:100%">
					<el-table-column type="selection" width="50"> </el-table-column>
					<el-table-column property="checkoutid" v-if="flag=='reassign'" min-width="120" label="检出人"
						align='center' show-overflow-tooltip>
					</el-table-column>
					<el-table-column min-width="80" property="caseno" label="受理号" align='center' show-overflow-tooltip>
					</el-table-column>
					<el-table-column min-width="100" property="routeidName" label="任务状态" align='center'
						show-overflow-tooltip>
					</el-table-column>
					<el-table-column min-width="100" property="tasklevel" :formatter="changeLevel" label="任务级别"
						align='center' sortable show-overflow-tooltip>
					</el-table-column>
					<el-table-column property="dealtime" min-width="160" label="最近处理时间" align='center'
						show-overflow-tooltip>
					</el-table-column>
<!-- 					<el-table-column min-width="160" property="sapptime" label="受理日期" align='center'
						show-overflow-tooltip> -->
					</el-table-column>
					<el-table-column min-width="120" property="taskno" :formatter="changeUpdateTime" label="任务上传时间"
						align='center' show-overflow-tooltip>
					</el-table-column>
					<el-table-column min-width="100" property="spolicyer" label="投保人" align='center'
						show-overflow-tooltip>
					</el-table-column>
					<el-table-column min-width="100" property="insured" label="被保人" align='center'
						show-overflow-tooltip>
					</el-table-column>
					<el-table-column min-width="120" property="orgname" label="分公司" align='center'
						show-overflow-tooltip>
					</el-table-column>
					<el-table-column min-width="100" property="risk" label="险种类型" align='center' show-overflow-tooltip>
					</el-table-column>
					<el-table-column min-width="120" property="crtableName" label="主合同名称" align='center'
						show-overflow-tooltip>
					</el-table-column>
					<el-table-column min-width="100" property="issamecustom" label="多保单标记" align='center'
						show-overflow-tooltip>
						<template slot-scope="scope">
							<el-link type="primary" @click="showMorePolicy(scope.row.policyholderno)"
								v-if="scope.row.issamecustom == '0'">{{scope.row.policyholderno}}
							</el-link>
							<span type="primary" v-if="scope.row.issamecustom != '0'">{{scope.row.policyholderno}}
							</span>
						</template>
					</el-table-column>
					<el-table-column min-width="120" property="historyhandler" label="历史处理人" align='center'
						show-overflow-tooltip>
					</el-table-column>
					<el-table-column min-width="50" label="备注" align='center' show-overflow-tooltip>
						<template slot-scope="scope">
							<el-link class="point" type="primary" @click="showRemark(scope.row.taskno)">备注
							</el-link>
						</template>
					</el-table-column>

					<el-table-column property="routeid" v-if="false"></el-table-column>
					<el-table-column property="insuredbrithday" v-if="false"></el-table-column>
					<el-table-column property="flagZT" v-if="false"></el-table-column>
					<el-table-column property="policyholderno" v-if="false"></el-table-column>
					<el-table-column property="policyholdername" v-if="false"></el-table-column>
					<el-table-column property="insuredno" v-if="false"></el-table-column>
					<el-table-column property="chdrnum" v-if="false"></el-table-column>
					<el-table-column property="tasklevel" v-if="false"></el-table-column>
				</el-table>
				<el-row>
					<el-col :span="24">
						<div class="pagination">
							<el-pagination background v-if='paginations.total > 0' :page-sizes="paginations.pageSizes"
								:page-size="paginations.pageSize" :layout="paginations.layout"
								:total="paginations.total" :current-page='paginations.pageIndex'
								@current-change='handleCurrentChange' @size-change='handleSizeChange'>
							</el-pagination>
						</div>
					</el-col>
				</el-row>
			</div>
		</div>
		<!-- 弹框 用户列表-->
		<el-dialog title="用户列表" :visible.sync="userListDialog" width="70%" center>
			<div class="table_container">
				<el-table ref="multipleUserTable" v-loading="loading" :data="taskUsers" highlight-current-row
					header-cell-class-name="table-header-class" style="width:100%">
					<el-table-column type="selection" width="55">
					</el-table-column>
					<el-table-column min-width="120" property="USERID" label="用户ID" align='center'
						show-overflow-tooltip>
					</el-table-column>
					<el-table-column min-width="120" property="USERNAME" label="用户名" align='center'
						show-overflow-tooltip>
					</el-table-column>
					<el-table-column min-width="120" property="STASKLEVEL" label="级别" align='center'
						show-overflow-tooltip>
					</el-table-column>
					<el-table-column min-width="120" property="ORGNAME" label="组织机构" align='center'
						show-overflow-tooltip>
					</el-table-column>
					<el-table-column min-width="120" property="HEBAOCOUNT" label="核保已有任务数" align='center'
						show-overflow-tooltip>
					</el-table-column>
					<el-table-column min-width="160" property="ZHHFCOUNT" label="照会回复已有任务数" align='center'
						show-overflow-tooltip>
					</el-table-column>
					<el-table-column min-width="120" label="在线标记" align='center' show-overflow-tooltip>
						<template slot-scope="scope">
							<div :class="scope.row.ISONLINE=='N'? 'fail':'success'">
								{{scope.row.ISONLINE =="N"?"离线":"在线"}}</div>
						</template>
					</el-table-column>
				</el-table>
			</div>
			<span slot="footer" class="dialog-footer">
				<el-button @click="userListDialog = false">取 消</el-button>
				<el-button class="Defaultbutton" v-antiSnake="2000" @click="distribute(1)">分 配</el-button>
			</span>
		</el-dialog>

    <!-- 弹框 总公司用户列表  -->
    <el-dialog title="总公司用户列表" :visible.sync="userListDialogHead" width="70%" center>
      <div class="table_container">
        <el-table ref="multipleUserTable2" v-loading="loading" :data="taskUsersHead" highlight-current-row
                  header-cell-class-name="table-header-class" style="width:100%">
          <el-table-column type="selection" width="55">
          </el-table-column>
          <el-table-column min-width="120" property="USERID" label="用户ID" align='center'
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column min-width="120" property="USERNAME" label="用户名" align='center'
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column min-width="120" property="STASKLEVEL" label="级别" align='center'
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column min-width="120" property="ORGNAME" label="组织机构" align='center'
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column min-width="120" property="HEBAOCOUNT" label="核保已有任务数" align='center'
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column min-width="160" property="ZHHFCOUNT" label="照会回复已有任务数" align='center'
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column min-width="120" label="在线标记" align='center' show-overflow-tooltip>
            <template slot-scope="scope">
              <div :class="scope.row.ISONLINE=='N'? 'fail':'success'">
                {{scope.row.ISONLINE =="N"?"离线":"在线"}}</div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
				<el-button @click="userListDialogHead = false">取 消</el-button>
				<el-button class="Defaultbutton" v-antiSnake="2000" @click="distribute(2)">分 配</el-button>
			</span>
    </el-dialog>

    <!-- 弹框 非总公司用户列表  -->
    <el-dialog title="非总公司用户列表" :visible.sync="userListDialogNotHead" width="70%" center>
      <div class="table_container">
        <el-table ref="multipleUserTable3" v-loading="loading" :data="taskUsersNotHead" highlight-current-row
                  header-cell-class-name="table-header-class" style="width:100%">
          <el-table-column type="selection" width="55">
          </el-table-column>
          <el-table-column min-width="120" property="USERID" label="用户ID" align='center'
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column min-width="120" property="USERNAME" label="用户名" align='center'
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column min-width="120" property="STASKLEVEL" label="级别" align='center'
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column min-width="120" property="ORGNAME" label="组织机构" align='center'
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column min-width="120" property="HEBAOCOUNT" label="核保已有任务数" align='center'
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column min-width="160" property="ZHHFCOUNT" label="照会回复已有任务数" align='center'
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column min-width="120" label="在线标记" align='center' show-overflow-tooltip>
            <template slot-scope="scope">
              <div :class="scope.row.ISONLINE=='N'? 'fail':'success'">
                {{scope.row.ISONLINE =="N"?"离线":"在线"}}</div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
				<el-button @click="userListDialogNotHead = false">取 消</el-button>
				<el-button class="Defaultbutton" v-antiSnake="2000" @click="distribute(3)">分 配</el-button>
			</span>
    </el-dialog>

		<!-- 弹框 排序信息-->
		<el-dialog title="排序选择" :visible.sync="showOrder" center>
			<el-checkbox-group v-model="orderList">
				<el-checkbox value="scantime" label="scantime">扫描时间</el-checkbox>
				<el-checkbox value="dealtime" label="dealtime">处理时间</el-checkbox>
				<el-checkbox value="apptime" label="apptime">受理时间</el-checkbox>
			</el-checkbox-group>
			<span slot="footer" class="dialog-footer">
				<el-button @click="showOrders">取 消</el-button>
				<el-button @click="showOrder = false">确定</el-button>
			</span>
		</el-dialog>

		<!-- 备注 -->
		<remark-list :business="'NB'" :taskNo="remarkTaskNo" :drawer="showRemarkFlag" @close="hideRemark"></remark-list>
		<!-- 同被保人多保单-->
		<more-policy-list :business="'NB'" :policyholderno="morePolicyPolicyholderno" :drawer="showMorePolicyFlag"
			@close="hideMorePolicy"></more-policy-list>

	</div>
</template>

<script>
	import {
		mapGetters
	} from 'vuex'
	import constant from '@/utils/constant';
	import {
		getSsyOrgMap
	} from '@/api/taskCenter/taskCommon';

	import {
		isCntainChinese,
		checkName
	} from '@/api/refund/RefundCommon';
	import taskConstants, {
		getSelectList
	} from '@/utils/taskConstants';
	import RemarkList from "../taskCenter/remarkList";
	import MorePolicyList from "../taskCenter/morePolicyList";
	import TaskConstants, {
		call
	} from "@/api/taskManager/common";
	import {
		getCompanylist,
		isSearchParamsEmpty,
	}
	from "@/api/taskManager/distributeTask"
	import {getMysqlInfo,getBranchByUserId} from '@/api/setting'
	export default {
		components: {
			RemarkList,
			MorePolicyList
		},
		directives: {
			// 注册
			// 自定义指令节流函数
			antiSnake: {
				// 自定义指令中钩子函数
				inserted: (el, binding) => {
					let timer = null
					el.addEventListener('click', () => {
						if (!timer) {
							el.disabled = true
							timer = setTimeout(() => {
								clearTimeout(timer)
								timer = null
								el.removeAttribute('disabled')
							}, binding.value)
						}
					})
				}
			}
		},
		data() {
			return {
				organ:'',
				mysqlUserInfo:{},//中台数据
				timing: 1000, //控制分配按钮的可点击时间
				userListDialog: false, //默认隐藏用户列表弹框
				userListDialogHead: false, //默认隐藏用户列表总公司弹框
				userListDialogNotHead: false, //默认隐藏用户列表非总公司弹框
				isShow: false,
				flag: "",
				ssyMap: {},
				levels: TaskConstants.level, //任务级别
				companylist: [], //分公司
				insmains: TaskConstants.insmain, //保单类型
				taskstatus_deassign: TaskConstants.taskstatus_deassign, //险种类型
				taskstatus_reassign: TaskConstants.taskstatus_reassign, //险种类型
				preChannelTypes: taskConstants.preChannelType, //渠道
				ssyMap: {},//机构对象
				taskUsers: [],
				taskUsersHead: [],
				taskUsersNotHead: [],
				orders: TaskConstants.orders,
				remarkTaskNo: "",
				showRemarkFlag: false,
				showOrder: false,
				morePolicyPolicyholderno: "",
				showMorePolicyFlag: false,
				orderList: [],
				emptySearchParams: {}, //空的查询
				// 查询条件
				searchParams: {
					"routeid": '',
					"type": '',
					"taskno": '',
					"channel":'',
					"companyid":'',
					"caseno": '',
					"chdrnum": "",
					"level": '',
					"begintime": '',
					"lasttime": '',
					"appbgntime": '',
					"appendtime": '',
					"tskbgntime": '',
					"tskendtime": '',
					"insured": '',
					"policyer": '',
					"orgId": '',
					"insmain": '',
					"taskstatus": '',
					"depotno": '',
					"appFrom": '',
					"serno": '',
					"historyHandler": '',
					"checkoutId": '',
					pageNumber: '',
					pageSize: '',
          secondInsuredName: "", // 第二被保人姓名
				},
				loading: false,
				tableData: [],
				appFroms: [],
				//需要给分页组件传的信息
				paginations: {
					total: 0, // 总数
					pageIndex: 1, // 当前位于哪页
					pageSize: 20, // 1页显示多少条
					pageSizes: [5, 10, 15, 20], //每页显示多少条
					layout: "total, sizes, prev, pager, next, jumper" // 翻页属性
				},
				pickerOptions1: {
					disabledDate(time) {
						return time.getTime() > Date.now();
					}
				}
			}
		},
		mounted() {
			getSsyOrgMap().then(data => this.ssyMap = data);
			this.appFroms = getSelectList(taskConstants.appFrom);
		},
		created() {
			/* 根据传入的不同souteid，页面转换成不同的类型，进行查询 */
			this.flag = this.$route.meta.flag;
			this.searchParams.routeid = this.flag;
			this.searchParams.type = this.flag;
			this.emptySearchParams = JSON.parse(JSON.stringify(this.searchParams));
			this.getUsers();
			getCompanylist().then(data => this.companylist = data);
			let userInfo = JSON.parse(sessionStorage.getItem("userInfo"));
			//获取核保员是否是总公司人员
			getMysqlInfo(userInfo.account).then(data =>{
				this.mysqlUserInfo = data;
			});
			getBranchByUserId(userInfo.account).then (data => this.organ = data);
		},
		activated() {
			document.onkeydown = (event) => {
				var e = event || window.event || arguments.callee.caller.arguments[0];
				if (e && e.keyCode == 113) {
					this.search();
				}
			};
		},
		methods: {
			showMorePolicy(morePolicyPolicyholderno) {
				this.morePolicyPolicyholderno = morePolicyPolicyholderno;
				this.showMorePolicyFlag = true;
			},
			hideMorePolicy() {
				this.morePolicyPolicyholderno = '';
				this.showMorePolicyFlag = false;
			},
			showRemark(taskNo) {
				this.remarkTaskNo = taskNo;
				this.showRemarkFlag = true;
			},
			hideRemark() {
				this.remarkTaskNo = "";
				this.showRemarkFlag = false;
			},
			clearTimeSetDefault(val) {
				if (val == null) {
					val = '';
				}
			},
			getOrgName(value) {
				for (var key in this.ssyMap) {
					if (this.ssyMap[key]["sbusiorgid"] && this.ssyMap[key]["sbusiorgid"] == value) {
						value = this.ssyMap[key]["sorgname"]
						break;
					}
				}
				return value;
			},
			getUsers() {
				call(TaskConstants.apis.getTaskUsers).then(result => {
					this.taskUsers = result.data;
          this.taskUsersHead = result.data.filter(item => item.headStatus == '0');
          this.taskUsersNotHead = result.data.filter(item => item.headStatus != '0');
				}).catch(error => {
					console.log(error)
				});

			},
			changeUpdateTime(row) {
				if (row.taskno != '') {
					let sTaskTime = row.taskno.substring(0, 14);
					let sTime = sTaskTime.substring(0, 4) + "-" + sTaskTime.substring(4, 6) + "-" + sTaskTime.substring(6,
						8);
					// sTime = sTime + " " + sTaskTime.substring(8, 10) + ":" + sTaskTime.substring(10, 12) + ":" + sTaskTime
					// 	.substring(
					// 		12, 14);
					return sTime;
				}
				return "";
			},
			changeLevel(row) {
				if (row.tasklevel == "") {
					return "0";
				}
				return row.tasklevel;
			},

			changeOnline(row) {
				if (row.ISONLINE == 'N') {
					return "离线";
				} else if (row.ISONLINE == 'Y') {
					return "在线";
				}
				return "";
			},
			showOrders() {
				this.showOrder = !this.showOrder;
				this.orderList = [];
			},
			showorhide() {
				this.isShow = !this.isShow;
			},
			userListGo() {
				this.userListDialog = true;
			},
      // 总公司按钮
      userListGoHead() {
        this.userListDialogHead = true;
      },
      // 非总公司按钮
      userListGoNotHead() {
        this.userListDialogNotHead = true;
      },
			show() {
				this.$store.dispatch('loading/CHANGE_LOADING', true);
			},
			cancle() {
				this.$store.dispatch('loading/CHANGE_LOADING', false)
			},
			resetSearch() {
				this.searchParams = JSON.parse(JSON.stringify(this.emptySearchParams));
			},
			search() {
				let isEmpty = this.searchParams.taskno == "" && this.searchParams.caseno == "" &&
					this.searchParams.level == "" && this.searchParams.begintime == "" &&
					this.searchParams.lasttime == "" && this.searchParams.appbgntime == "" &&
					this.searchParams.appendtime == "" && this.searchParams.tskbgntime == "" &&
					this.searchParams.tskendtime == "" && this.searchParams.insured == "" &&
					this.searchParams.policyer == "" && this.searchParams.orgId == "" &&
					this.searchParams.insmain == "" && this.searchParams.taskstatus == "" &&
					this.searchParams.channel ==""&&
					this.searchParams.depotno == "" && this.searchParams.appFrom == "" && this.searchParams
					.historyHandler == "" && this.searchParams.serno == "" && this.searchParams.chdrnum == ""
          && this.searchParams.secondInsuredName == "";
				if (isEmpty || (isEmpty && this.flag == 'reassign' && this.searchParams.checkoutId == "")) {
					this.$message.error("请选择一项查询条件！");
					return;
				}
				if (this.searchParams.caseno != "" && isCntainChinese(this.searchParams.caseno)) {
					this.$message.error("请正确输入受理号！");
					return;
				}
				if (this.searchParams.depotno != "" && isCntainChinese(this.searchParams.depotno)) {
					this.$message.error("请正确输入存仓号！");
					return;
				}
				if (this.searchParams.historyHandler != "" && isCntainChinese(this.searchParams.historyHandler)) {
					this.$message.error("请正确输入历史处理人员！");
					return;
				}
				if (this.searchParams.insured != "" && checkName(this.searchParams.insured)) {
					this.$message.error("请正确输入被保人姓名！");
					return;
				}
				if (this.searchParams.policyer != "" && checkName(this.searchParams.policyer)) {
					this.$message.error("请正确输入投保人姓名！");
					return;
				}
				if (this.searchParams.tskbgntime && this.searchParams.tskendtime) {
					let oDate1 = new Date(this.searchParams.tskbgntime);
					let oDate2 = new Date(this.searchParams.tskendtime);
					if (oDate1.getTime() > oDate2.getTime()) {
						this.$message.error("任务起始时间不能大于结束时间！");
						return;
					}
				}
				if (this.searchParams.begintime && this.searchParams.lasttime) {
					let oDate3 = new Date(this.searchParams.begintime);
					let oDate4 = new Date(this.searchParams.lasttime);
					if (oDate3.getTime() > oDate4.getTime()) {
						this.$message.error("扫描起始时间不能大于结束时间！");
						return;
					}
				}
				if (this.searchParams.appbgntime && this.searchParams.appendtime) {
					let oDate5 = new Date(this.searchParams.appbgntime);
					let oDate6 = new Date(this.searchParams.appendtime);
					if (oDate5.getTime() > oDate6.getTime()) {
						this.$message.error("受理起始时间不能大于结束时间！");
						return;
					}
				}
				this.paginations.pageIndex = 1;
				this.paginations.pageSize = 20;
				this.getList();
			},
			// 查询列表
			getList() {
				this.paginations.total = 0;
				this.tableData = [];
				this.searchParams.pageNumber = this.paginations.pageIndex;
				this.searchParams.pageSize = this.paginations.pageSize;
				this.show();
				this.searchParams['orders'] = this.orderList;
				call(TaskConstants.apis['queryList'], this.searchParams, "post").then(result => {
					if (result.resultCode == constant.SUCCESS && result.data && result.data.list.length) {
						let pageData = result.data;
						this.paginations.total = pageData.total;
						this.paginations.currentPage = pageData.pageNum;
						this.tableData = pageData.list;
						this.tableData.forEach(item => {
							item["orgname"] = this.getOrgName(item.orgname);
						})
					}
					// else {
					// 	this.$message.error("无符合条件任务！");
					// }
					this.cancle();
				}).catch(error => {
					console.log(error);
					this.cancle();
				});
			},
			//分配任务
			distribute(num) {
				let arrTaskList = [];
				let arrUserList = [];
        if (num == 1) {
          this.$refs.multipleUserTable.selection.forEach(item => {
            arrUserList.push(item);
          });
        } else if (num == 2) {
          this.$refs.multipleUserTable2.selection.forEach(item => {
            arrUserList.push(item);
          });
        } else if (num == 3) {
          this.$refs.multipleUserTable3.selection.forEach(item => {
            arrUserList.push(item);
          });
        }

				this.$refs.multipleDataTable.selection.forEach(item => {
					arrTaskList.push(item);
				});
				if (arrUserList.length == 0) {
					this.$message.error("请选择用户！");
					return;
				}
				if (arrTaskList.length == 0) {
					this.$message.error("请选择需要分配的任务！");
					return;
				}
				//核保员需求,增加机构校验拦截
				if(this.mysqlUserInfo.headStatus != "0") {
						//非总公司人员，只能分配本公司的单，禁止操作其他公司的

					let isContains = false;
					arrTaskList.forEach( item =>{
							if(item.organ != this.organ) {
								isContains = true;
							}
					})
					if(isContains){
						this.$message({
							message: '核保员非总公司人员，且待分配的单中包含不是您所属机构的保单，不允许手动分单!!',
							type: 'error'
						});
						return false;
					}
				}
				for (var i = 0; i < arrUserList.length; i++) {
					let tmpuser = arrUserList[i];
					let online = tmpuser.ISONLINE;
					if (online != 'Y') {
						if (!confirm("该用户不在线，是否确定继续执行分配?")) {
							return;
						}
					}
				}
				//核保员级别是否相同
				let lm = [];
				for (i = 0; i < arrUserList.length; i++) {
					let tmpuser = arrUserList[i];
					let hbLevel = tmpuser.STASKLEVEL;
					if (hbLevel) {
						if (lm.indexOf(hbLevel) <= -1) {
							lm.push(hbLevel);
						}
					}
				}
				let size = lm.length;
				if (size > 1) {
					if (!confirm("核保员级别不一致，是否继续执行分配?")) {
						return;
					}
				}
				//如果人的级别相同，取级别值，遍历单的级别，如有任何不一致的，提示，可强制
				if (size == 1) {
					let result = "";
					let resultLevel = "";
					for (var j = 0; j < arrTaskList.length; j++) {
						let tmptask = arrTaskList[j];
						let taskLevel = tmptask.tasklevel;
						let level = arrUserList[0].STASKLEVEL;
						if (parseInt(level) < parseInt(taskLevel)) {
							result = result + "、" + "[受理号：" + tmptask.caseno + "]";
						} else if (parseInt(level) != parseInt(taskLevel)) {
							resultLevel = resultLevel + "、" + "[受理号：" + tmptask.caseno + "]";
						}
					}
					let checkflag = true;
					if (result != "") {
						result = result.substring(1, result.length);
						if (!confirm("该单" + result + "任务级别超出核保员的授权级别，是否确定继续执行分配?")) {
							return;
						}
						checkflag = false;
					}
					if (resultLevel != "" && checkflag == true) {
						resultLevel = resultLevel.substring(1, resultLevel.length);
						if (!confirm("该单" + resultLevel + "任务级别与核保员的授权级别不相等，是否确定继续执行分配?")) {
							return;
						}
					}
				}
				//增加保单的历史核保员是否存在于分派员选择的核保员列表的判断
				let result = "";
				for (var k = 0; k < arrTaskList.length; k++) {
					let tmptask = arrTaskList[k];
					let routedId = tmptask.routeid;
					let acceptid = tmptask.caseno;
					let historyHandler = tmptask.historyHandler;
					if (routedId == "hbassign" && historyHandler) {
						arrUserList.forEach(user => {
							if (user.USERNAME.indexOf(historyHandler) == -1 || user.USERID.indexOf(
								historyHandler) == -1) {
								result = result + "受理号[" + acceptid + "]存在历史核保员[" + historyHandler + "]、"
							}
						});
					}
				}
				if (result) {
					result = result.substring(0, result.length - 1);
					if (!confirm(result + "不在选择的核保员列表中,是否继续执行分配?")) {
						return;
					}
				}
				let param = {
					"flag": this.flag,
					"staskList": arrTaskList,
					"suserList": arrUserList
				}
				this.show();
				call(TaskConstants.apis["distributeTask"], param, "post").then(result => {
					if (result.resultCode == constant.SUCCESS) {
						this.$message.success("任务分配成功！");
            if (num == 1) {
              this.$refs.multipleUserTable.clearSelection();
            } else if (num == 2) {
              this.$refs.multipleUserTable2.clearSelection();
            } else if (num == 3) {
              this.$refs.multipleUserTable3.clearSelection();
            }
						this.paginations.pageIndex = 1;
						this.paginations.pageSize = 20;
						this.getList();
						this.getUsers();
					}
					// else {
					// 	this.$message.error(result.resultMsg);
					// }
					console.log(result);
				}).catch(err => {
					console.log(err);
				})
				this.userListDialog = false;
				this.userListDialogHead = false;
				this.userListDialogNotHead = false;
				this.cancle();
			},
			// 每页多少条切换
			handleSizeChange(pageSize) {
				this.paginations.pageSize = pageSize;
				this.getList();
			},
			// 上下分页
			handleCurrentChange(page) {
				this.paginations.pageIndex = page;
				this.getList();
			},
		},
		computed: {
			...mapGetters(['tags']),
			reload() {
				return this.$store.state.loading.reload;
			}
		},
	}
</script>
<style>
	.el-table .red {
		color: red
	}

	.el-table .green {
		color: green
	}

	.el-table .blue {
		color: blue
	}

	.el-table .orange {
		color: orange
	}

	.el-table .default {
		color: white
	}
</style>
<style lang="less" scoped>
	.success {
		color: ''
	}

	.fail {
		color: #C0C0C0
	}

	.fillcontain {
		padding-bottom: 0;

		.fastQuery {
			padding: 15px 20px 10px 20px;
			background: #fff;
			border-bottom: 1px solid #e1e1e1;

			.fastQuery_title {
				color: #666;
				padding: 6px 0px;
			}

			.fastQuery_item {
				margin: 0 10px;
			}

			.item_default {
				.el-button {
					color: #409EFF !important;
					border-color: #c6e2ff !important;
					background-color: #ecf5ff !important;
				}

			}

			.moreCondition {
				color: #68a3fc;
				cursor: pointer;
				padding: 6px 0px;

				.el-icon-d-arrow-right {
					transform: rotate(90deg);
				}

				.el-icon-d-arrow-left {
					transform: rotate(-90deg);
				}
			}
		}
	}

	.contain {
		background: #fff;
		padding: 10px;
		margin-bottom: 20px;
	}

	.pagination {
		padding: 10px 20px;
		text-align: right;
	}

	.operationIcon {
		// padding: 12px;
		border: 1px solid #e5e5e5;
		border-radius: 50%;
		width: 22px;
		height: 22px;
		display: inline-block;
		cursor: pointer;
		box-shadow: 0 0 3px #f9f9f9;
	}


	.search_container {
		padding: 20px 20px 0 20px;
		//    border-top: 1px solid #e1e1e1;
	}

	.common-box {
		// padding-bottom: 15px;
	}

	.common-lab {
		line-height: normal !important;
		text-align: right;

		.labelName {
			text-align: right;
		}
	}
</style>
